package com.example.application.views.change;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.annotation.security.PermitAll;

import com.example.application.compose.Button_Deal;
import com.example.application.views.MainLayout;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.html.H1;
import com.vaadin.flow.component.html.H2;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.select.Select;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;

@Route(value = "decimal_Conversion", layout = MainLayout.class)
@PageTitle("进制转换功能")
@PermitAll
public class Decimal_Conversion extends VerticalLayout {
    private List<String> select_items = new ArrayList<>(
        Arrays.asList("8位", "16位", "32位"));
    

    public Decimal_Conversion() {
        H1 title=new H1("原码、反码、补码计算器方便开发者的小工具");
        H2 subtitle=new H2("方便开发者的小工具");

        add(title,subtitle);

        Select<String> select = new Select<>();
        select.setLabel("选择位数");
        select.setItems(select_items);
        select.setValue(select_items.get(0));
        
        add(select);

        TextField field = new TextField();
field.setLabel("请输入整数");
field.setHelperText("范围0-1000");
// field.setPlaceholder("Placeholder");
// field.setTooltipText("Tooltip text");
field.setClearButtonVisible(true);
field.setPrefixComponent(VaadinIcon.VAADIN_H.create());
field.setSuffixComponent(new Span("(:)"));

        add(field);
        List<TextField> t=getThree();
        // t.forEach(add(this));
        // add(t);
        t.forEach((e) -> {
            add(e);
        });

        Button b2=new Button("计算整个结果");
        add(b2);
        b2.addClickListener(event->{
            // t.get(0).setValue("HI");
            getResult(t,field.getValue());
        });

    }

    private  List<TextField> getThree(){
        List<TextField> three=new ArrayList<>();
        three.add(getOne("原码"));
        three.add(getOne("反码"));
        three.add(getOne("补码"));
        return three;

    }

    private  void getResult(List<TextField> three,String value){
        

    }
    
    private  TextField getOne(String label_name){
        TextField readonlyField1 = new TextField();
        readonlyField1.setReadOnly(true);
        readonlyField1.setLabel(label_name);
        readonlyField1.clear();
        return readonlyField1;

    }
}
